package com.example.yuejian21.nongfusanquan.yuejian21.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Myactivitybean;
import com.squareup.picasso.Picasso;

import java.util.List;


/**
 * Created by Administrator on 2017/10/20.
 */

public class MyactivityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;

    public MyactivityAdapter(Context mContext, List mDataList) {
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_my_order, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Myactivitybean entity = (Myactivitybean) mDataList.get(position);
        if (null == entity)
            return;

        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.createtime.setText(entity.getCreatetime());
        viewHolder.a_name.setText(entity.getA_name());
        viewHolder.a_time.setText(entity.getA_time());
        viewHolder.a_price.setText("￥" + entity.getA_price() + "");
        final String t_picture = "http://10.0.2.2/yuejian14/Public/Admin/activitypicture/" + entity.getA_picture();
        //System.out.print("pic");
        if (!t_picture.equals("")) {
            Picasso.with(mContex).load(t_picture).error(R.drawable.ic_add).into(viewHolder.a_pic);
        }

    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView a_pic;
        TextView createtime, a_name, a_price, a_time;

        public ViewHolder(View itemView) {
            super(itemView);
            createtime = (TextView) itemView.findViewById(R.id.createtime);
            a_time = (TextView) itemView.findViewById(R.id.time);
            a_name = (TextView) itemView.findViewById(R.id.name);
            a_price = (TextView) itemView.findViewById(R.id.price);
            a_pic = (ImageView) itemView.findViewById(R.id.pic);


        }
    }
}
